Artificial Intelligence Nanodegree

Computer Vision Capstone

Project: Facial Keypoint Detection


Welcome to the final Computer Vision project in the Artificial Intelligence Nanodegree program!

In this project, you’ll combine your knowledge of computer vision techniques and deep learning to build and end-to-end facial keypoint recognition system! Facial keypoints include points around the eyes, nose, and mouth on any face and are used in many applications, from facial tracking to emotion recognition.

There are three main parts to this project:

Part 1 : Investigating OpenCV, pre-processing, and face detection

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!


*Here's what you need to know to complete the project:

  1. In this notebook, some template code has already been provided for you, and you will need to implement additional functionality to successfully complete this project. You will not need to modify the included code beyond what is requested.

    a. Sections that begin with '(IMPLEMENTATION)' in the header indicate that the following block of code will require additional functionality which you must provide. Instructions will be provided for each section, and the specifics of the implementation are marked in the code block with a 'TODO' statement. Please be sure to read the instructions carefully!

  1. In addition to implementing code, there will be questions that you must answer which relate to the project and your implementation.

    a. Each section where you will answer a question is preceded by a 'Question X' header.

    b. Carefully read each question and provide thorough answers in the following text boxes that begin with 'Answer:'.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. Markdown cells can be edited by double-clicking the cell to enter edit mode.

The rubric contains optional suggestions for enhancing the project beyond the minimum requirements. If you decide to pursue the "(Optional)" sections, you should include the code in this IPython notebook.

Your project submission will be evaluated based on your answers to each of the questions and the code implementations you provide.

Steps to Complete the Project

Each part of the notebook is further broken down into separate steps. Feel free to use the links below to navigate the notebook.

In this project you will get to explore a few of the many computer vision algorithms built into the OpenCV library. This expansive computer vision library is now almost 20 years old and still growing!

The project itself is broken down into three large parts, then even further into separate steps. Make sure to read through each step, and complete any sections that begin with '(IMPLEMENTATION)' in the header; these implementation sections may contain multiple TODOs that will be marked in code. For convenience, we provide links to each of these steps below.

Part 1 : Investigating OpenCV, pre-processing, and face detection

  • Step 0: Detect Faces Using a Haar Cascade Classifier
  • Step 1: Add Eye Detection
  • Step 2: De-noise an Image for Better Face Detection
  • Step 3: Blur an Image and Perform Edge Detection
  • Step 4: Automatically Hide the Identity of an Individual

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

  • Step 5: Create a CNN to Recognize Facial Keypoints
  • Step 6: Compile and Train the Model
  • Step 7: Visualize the Loss and Answer Questions

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!

  • Step 8: Build a Robust Facial Keypoints Detector (Complete the CV Pipeline)

Step 0: Detect Faces Using a Haar Cascade Classifier

Have you ever wondered how Facebook automatically tags images with your friends' faces? Or how high-end cameras automatically find and focus on a certain person's face? Applications like these depend heavily on the machine learning task known as face detection - which is the task of automatically finding faces in images containing people.

At its root face detection is a classification problem - that is a problem of distinguishing between distinct classes of things. With face detection these distinct classes are 1) images of human faces and 2) everything else.

We use OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on github. We have downloaded one of these detectors and stored it in the detector_architectures directory.

Import Resources

In the next python cell, we load in the required libraries for this section of the project.

In [1]:
# Import required libraries for this section

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import math
import cv2                     # OpenCV library for computer vision
from PIL import Image
import time 

Next, we load in and display a test image for performing face detection.

Note: by default OpenCV assumes the ordering of our image's color channels are Blue, then Green, then Red. This is slightly out of order with most image types we'll use in these experiments, whose color channels are ordered Red, then Green, then Blue. In order to switch the Blue and Red channels of our test image around we will use OpenCV's cvtColor function, which you can read more about by checking out some of its documentation located here. This is a general utility function that can do other transformations too like converting a color image to grayscale, and transforming a standard color image to HSV color space.

In [168]:
# Load in color image for face detection
image = cv2.imread('images/test_image_1.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot our image using subplots to specify a size and title
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[168]:
<matplotlib.image.AxesImage at 0x23c92237d68>

There are a lot of people - and faces - in this picture. 13 faces to be exact! In the next code cell, we demonstrate how to use a Haar Cascade classifier to detect all the faces in this test image.

This face detector uses information about patterns of intensity in an image to reliably detect faces under varying light conditions. So, to use this face detector, we'll first convert the image from color to grayscale.

Then, we load in the fully trained architecture of the face detector -- found in the file haarcascade_frontalface_default.xml - and use it on our image to find faces!

To learn more about the parameters of the detector see this post.

In [169]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[169]:
<matplotlib.image.AxesImage at 0x23c922a2cc0>

In the above code, faces is a numpy array of detected faces, where each row corresponds to a detected face. Each detected face is a 1D array with four entries that specifies the bounding box of the detected face. The first two entries in the array (extracted in the above code as x and y) specify the horizontal and vertical positions of the top left corner of the bounding box. The last two entries in the array (extracted here as w and h) specify the width and height of the box.


Step 1: Add Eye Detections

There are other pre-trained detectors available that use a Haar Cascade Classifier - including full human body detectors, license plate detectors, and more. A full list of the pre-trained architectures can be found here.

To test your eye detector, we'll first read in a new test image with just a single face.

In [272]:
# Load in color image for face detection
image = cv2.imread('images/james.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot the RGB image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[272]:
<matplotlib.image.AxesImage at 0x23c926ebf28>

Notice that even though the image is a black and white image, we have read it in as a color image and so it will still need to be converted to grayscale in order to perform the most accurate face detection.

So, the next steps will be to convert this image to grayscale, then load OpenCV's face detector and run it with parameters that detect this face accurately.

In [273]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.25, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_with_detections)
Number of faces detected: 1
Out[273]:
<matplotlib.image.AxesImage at 0x23c935410b8>

(IMPLEMENTATION) Add an eye detector to the current face detection setup.

A Haar-cascade eye detector can be included in the same way that the face detector was and, in this first task, it will be your job to do just this.

To set up an eye detector, use the stored parameters of the eye cascade detector, called haarcascade_eye.xml, located in the detector_architectures subdirectory. In the next code cell, create your eye detector and store its detections.

A few notes before you get started:

First, make sure to give your loaded eye detector the variable name

eye_cascade

and give the list of eye regions you detect the variable name

eyes

Second, since we've already run the face detector over this image, you should only search for eyes within the rectangular face regions detected in faces. This will minimize false detections.

Lastly, once you've run your eye detector over the facial detection region, you should display the RGB image with both the face detection boxes (in red) and your eye detections (in green) to verify that everything works as expected.

In [274]:
# Make a copy of the original image to plot rectangle detections
image_with_detections = np.copy(image)   

# Loop over the detections and draw their corresponding face detection boxes
for (x,y,w,h) in faces:
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(255,0,0), 3)  
    
# Do not change the code above this comment!

    
## TODO: Add eye detection, using haarcascade_eye.xml, to the current face detector algorithm
eye_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_eye.xml')

eyes = eye_cascade.detectMultiScale(gray, 1.1, 6)

## TODO: Loop over the eye detections and draw their corresponding boxes in green on image_with_detections
for (x,y,w,h) in eyes:
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(0,255,0), 2)

# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face & Eye Detection')
ax1.imshow(image_with_detections)
Out[274]:
<matplotlib.image.AxesImage at 0x23c925dc390>

(Optional) Add face and eye detection to your laptop camera

It's time to kick it up a notch, and add face and eye detection to your laptop's camera! Afterwards, you'll be able to show off your creation like in the gif shown below - made with a completed version of the code!

Notice that not all of the detections here are perfect - and your result need not be perfect either. You should spend a small amount of time tuning the parameters of your detectors to get reasonable results, but don't hold out for perfection. If we wanted perfection we'd need to spend a ton of time tuning the parameters of each detector, cleaning up the input image frames, etc. You can think of this as more of a rapid prototype.

The next cell contains code for a wrapper function called laptop_camera_face_eye_detector that, when called, will activate your laptop's camera. You will place the relevant face and eye detection code in this wrapper function to implement face/eye detection and mark those detections on each image frame that your camera captures.

Before adding anything to the function, you can run it to get an idea of how it works - a small window should pop up showing you the live feed from your camera; you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [2]:
### Add face and eye detection to this laptop camera function 
# Make sure to draw out all faces/eyes found in each frame on the shown video feed

import cv2
import time 

# wrapper function for face/eye detection with your laptop camera
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep the video stream open
    while rval:
        # Plot the image from camera with all the face and eye detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            # Make sure window closes on OSx
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
In [3]:
# Call the laptop camera face/eye detector function above
laptop_camera_go()

Step 2: De-noise an Image for Better Face Detection

Image quality is an important aspect of any computer vision task. Typically, when creating a set of images to train a deep learning network, significant care is taken to ensure that training images are free of visual noise or artifacts that hinder object detection. While computer vision algorithms - like a face detector - are typically trained on 'nice' data such as this, new test data doesn't always look so nice!

When applying a trained computer vision algorithm to a new piece of test data one often cleans it up first before feeding it in. This sort of cleaning - referred to as pre-processing - can include a number of cleaning phases like blurring, de-noising, color transformations, etc., and many of these tasks can be accomplished using OpenCV.

In this short subsection we explore OpenCV's noise-removal functionality to see how we can clean up a noisy image, which we then feed into our trained face detector.

Create a noisy image to work with

In the next cell, we create an artificial noisy version of the previous multi-face image. This is a little exaggerated - we don't typically get images that are this noisy - but image noise, or 'grainy-ness' in a digitial image - is a fairly common phenomenon.

In [282]:
# Load in the multi-face test image again
image = cv2.imread('images/test_image_1.jpg')

# Convert the image copy to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Make an array copy of this image
image_with_noise = np.asarray(image)

# Create noise - here we add noise sampled randomly from a Gaussian distribution: a common model for noise
noise_level = 40
noise = np.random.randn(image.shape[0],image.shape[1],image.shape[2])*noise_level

# Add this noise to the array image copy
image_with_noise = image_with_noise + noise

# Convert back to uint8 format
image_with_noise = np.asarray([np.uint8(np.clip(i,0,255)) for i in image_with_noise])

# Plot our noisy image!
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image')
ax1.imshow(image_with_noise)
Out[282]:
<matplotlib.image.AxesImage at 0x23c93700eb8>

In the context of face detection, the problem with an image like this is that - due to noise - we may miss some faces or get false detections.

In the next cell we apply the same trained OpenCV detector with the same settings as before, to see what sort of detections we get.

In [283]:
# Convert the RGB  image to grayscale
gray_noise = cv2.cvtColor(image_with_noise, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_noise, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_with_noise)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 11
Out[283]:
<matplotlib.image.AxesImage at 0x23c935c9b70>

With this added noise we now miss one of the faces!

(IMPLEMENTATION) De-noise this image for better face detection

Time to get your hands dirty: using OpenCV's built in color image de-noising functionality called fastNlMeansDenoisingColored - de-noise this image enough so that all the faces in the image are properly detected. Once you have cleaned the image in the next cell, use the cell that follows to run our trained face detector over the cleaned image to check out its detections.

You can find its official documentation here and a useful example here.

Note: you can keep all parameters except photo_render fixed as shown in the second link above. Play around with the value of this parameter - see how it affects the resulting cleaned image.

In [284]:
## TODO: Use OpenCV's built in color image de-noising function to clean up our noisy image!

# your final de-noised image (should be RGB)
denoised_image = cv2.fastNlMeansDenoisingColored(image_with_noise, None, 20, 20)

# Plot our denoised image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Denoised Image')
ax1.imshow(denoised_image)
Out[284]:
<matplotlib.image.AxesImage at 0x23c9365bb00>
In [285]:
## TODO: Run the face detector on the de-noised image to improve your detections and display the result

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Make a copy of the original denoised image to plot rectangle detections
image_with_detections = np.copy(denoised_image)   

#  to grayscale
gray_denoised_image = cv2.cvtColor(denoised_image, cv2.COLOR_RGB2GRAY)

# Detect the face(s) in the greyscale denoised image
faces = face_cascade.detectMultiScale(gray_denoised_image, 1.3,6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Display each face rectangle in the denoised image
for (x_face,y_face,w_face,h_face) in faces:
    cv2.rectangle(image_with_detections, (x_face,y_face), (x_face+w_face,y_face+h_face), (255,0,0), 3)  

# Plot the denoised image with all the face detections marked
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Denoised Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[285]:
<matplotlib.image.AxesImage at 0x23c936c0b00>

Step 3: Blur an Image and Perform Edge Detection

Now that we have developed a simple pipeline for detecting faces using OpenCV - let's start playing around with a few fun things we can do with all those detected faces!

Importance of Blur in Edge Detection

Edge detection is a concept that pops up almost everywhere in computer vision applications, as edge-based features (as well as features built on top of edges) are often some of the best features for e.g., object detection and recognition problems.

Edge detection is a dimension reduction technique - by keeping only the edges of an image we get to throw away a lot of non-discriminating information. And typically the most useful kind of edge-detection is one that preserves only the important, global structures (ignoring local structures that aren't very discriminative). So removing local structures / retaining global structures is a crucial pre-processing step to performing edge detection in an image, and blurring can do just that.

Below is an animated gif showing the result of an edge-detected cat taken from Wikipedia, where the image is gradually blurred more and more prior to edge detection. When the animation begins you can't quite make out what it's a picture of, but as the animation evolves and local structures are removed via blurring the cat becomes visible in the edge-detected image.

Edge detection is a convolution performed on the image itself, and you can read about Canny edge detection on this OpenCV documentation page.

Canny edge detection

In the cell below we load in a test image, then apply Canny edge detection on it. The original image is shown on the left panel of the figure, while the edge-detected version of the image is shown on the right. Notice how the result looks very busy - there are too many little details preserved in the image before it is sent to the edge detector. When applied in computer vision applications, edge detection should preserve global structure; doing away with local structures that don't help describe what objects are in the image.

In [214]:
# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[214]:
<matplotlib.image.AxesImage at 0x23c825d02b0>

Without first blurring the image, and removing small, local structures, a lot of irrelevant edge content gets picked up and amplified by the detector (as shown in the right panel above).

(IMPLEMENTATION) Blur the image then perform edge detection

In the next cell, you will repeat this experiment - blurring the image first to remove these local structures, so that only the important boudnary details remain in the edge-detected image.

Blur the image by using OpenCV's filter2d functionality - which is discussed in this documentation page - and use an averaging kernel of width equal to 4.

In [291]:
### TODO: Blur the test imageusing OpenCV's filter2d functionality, 
# Use an averaging kernel, and a kernel width equal to 4

# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Blur using filter2d() with kernel 4
kernel_4 = np.ones((4,4), np.float32)/(4*4)
blur_gray = cv2.filter2D(gray, -1, kernel_4 )

## TODO: Then perform Canny edge detection and display the output
# Perform Canny edge detection
edges = cv2.Canny(blur_gray,100,250)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[291]:
<matplotlib.image.AxesImage at 0x23c95beadd8>

Step 4: Automatically Hide the Identity of an Individual

If you film something like a documentary or reality TV, you must get permission from every individual shown on film before you can show their face, otherwise you need to blur it out - by blurring the face a lot (so much so that even the global structures are obscured)! This is also true for projects like Google's StreetView maps - an enormous collection of mapping images taken from a fleet of Google vehicles. Because it would be impossible for Google to get the permission of every single person accidentally captured in one of these images they blur out everyone's faces, the detected images must automatically blur the identity of detected people. Here's a few examples of folks caught in the camera of a Google street view vehicle.

Read in an image to perform identity detection

Let's try this out for ourselves. Use the face detection pipeline built above and what you know about using the filter2D to blur and image, and use these in tandem to hide the identity of the person in the following image - loaded in and printed in the next cell.

In [292]:
# Load in the image
image = cv2.imread('images/gus.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[292]:
<matplotlib.image.AxesImage at 0x23c95c55898>

(IMPLEMENTATION) Use blurring to hide the identity of an individual in an image

The idea here is to 1) automatically detect the face in this image, and then 2) blur it out! Make sure to adjust the parameters of the averaging blur filter to completely obscure this person's identity.

In [293]:
## TODO: Implement face detection
# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

blur_face = np.copy(image)

# Denoise  
denoised_image = cv2.fastNlMeansDenoisingColored(image, None, 20, 20)

# To grayscale
gray = cv2.cvtColor(denoised_image, cv2.COLOR_RGB2GRAY)

# Detect the face(s) 
faces = face_cascade.detectMultiScale(gray, 1.3, 6)

## TODO: Blur the bounding box around each detected face using an averaging filter and display the result

# Create a strong averaging filter kernel
kernel_96 = np.ones((96,96), np.float32)/(96*96)
offset = 30 # additional offset to stretch the blur a little beyond the face region, just in case

for (x,y,w,h) in faces:
    blur_face[y-offset:y+h+offset, x:x+w] = cv2.filter2D(image[y-offset:y+h+offset, x:x+w], -1, kernel_96)

# Plot the image with the face(s) blurred
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Image with Blurred Face')
ax1.imshow(blur_face)
Out[293]:
<matplotlib.image.AxesImage at 0x23c95cb8978>

(Optional) Build identity protection into your laptop camera

In this optional task you can add identity protection to your laptop camera, using the previously completed code where you added face detection to your laptop camera - and the task above. You should be able to get reasonable results with little parameter tuning - like the one shown in the gif below.

As with the previous video task, to make this perfect would require significant effort - so don't strive for perfection here, strive for reasonable quality.

The next cell contains code a wrapper function called laptop_camera_identity_hider that - when called - will activate your laptop's camera. You need to place the relevant face detection and blurring code developed above in this function in order to blur faces entering your laptop camera's field of view.

Before adding anything to the function you can call it to get a hang of how it works - a small window will pop up showing you the live feed from your camera, you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [ ]:
### Insert face detection and blurring code into the wrapper below to create an identity protector on your laptop!
import cv2
import time 

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [ ]:
# Run laptop identity hider
laptop_camera_go()

Step 5: Create a CNN to Recognize Facial Keypoints

OpenCV is often used in practice with other machine learning and deep learning libraries to produce interesting results. In this stage of the project you will create your own end-to-end pipeline - employing convolutional networks in keras along with OpenCV - to apply a "selfie" filter to streaming video and images.

You will start by creating and then training a convolutional network that can detect facial keypoints in a small dataset of cropped images of human faces. We then guide you towards OpenCV to expanding your detection algorithm to more general images. What are facial keypoints? Let's take a look at some examples.

Facial keypoints (also called facial landmarks) are the small blue-green dots shown on each of the faces in the image above - there are 15 keypoints marked in each image. They mark important areas of the face - the eyes, corners of the mouth, the nose, etc. Facial keypoints can be used in a variety of machine learning applications from face and emotion recognition to commercial applications like the image filters popularized by Snapchat.

Below we illustrate a filter that, using the results of this section, automatically places sunglasses on people in images (using the facial keypoints to place the glasses correctly on each face). Here, the facial keypoints have been colored lime green for visualization purposes.

Make a facial keypoint detector

But first things first: how can we make a facial keypoint detector? Well, at a high level, notice that facial keypoint detection is a regression problem. A single face corresponds to a set of 15 facial keypoints (a set of 15 corresponding $(x, y)$ coordinates, i.e., an output point). Because our input data are images, we can employ a convolutional neural network to recognize patterns in our images and learn how to identify these keypoint given sets of labeled data.

In order to train a regressor, we need a training set - a set of facial image / facial keypoint pairs to train on. For this we will be using this dataset from Kaggle. We've already downloaded this data and placed it in the data directory. Make sure that you have both the training and test data files. The training dataset contains several thousand $96 \times 96$ grayscale images of cropped human faces, along with each face's 15 corresponding facial keypoints (also called landmarks) that have been placed by hand, and recorded in $(x, y)$ coordinates. This wonderful resource also has a substantial testing set, which we will use in tinkering with our convolutional network.

To load in this data, run the Python cell below - notice we will load in both the training and testing sets.

The load_data function is in the included utils.py file.

In [5]:
from utils import *

# Load training set
X_train, y_train = load_data()
print("X_train.shape == {}".format(X_train.shape))
print("y_train.shape == {}; y_train.min == {:.3f}; y_train.max == {:.3f}".format(
    y_train.shape, y_train.min(), y_train.max()))

# Load testing set
X_test, _ = load_data(test=True)
print("X_test.shape == {}".format(X_test.shape))
X_train.shape == (2140, 96, 96, 1)
y_train.shape == (2140, 30); y_train.min == -0.920; y_train.max == 0.996
X_test.shape == (1783, 96, 96, 1)

The load_data function in utils.py originates from this excellent blog post, which you are strongly encouraged to read. Please take the time now to review this function. Note how the output values - that is, the coordinates of each set of facial landmarks - have been normalized to take on values in the range $[-1, 1]$, while the pixel values of each input point (a facial image) have been normalized to the range $[0,1]$.

Note: the original Kaggle dataset contains some images with several missing keypoints. For simplicity, the load_data function removes those images with missing labels from the dataset. As an optional extension, you are welcome to amend the load_data function to include the incomplete data points.

Visualize the Training Data

Execute the code cell below to visualize a subset of the training data.

In [6]:
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_train[i], y_train[i], ax)

For each training image, there are two landmarks per eyebrow (four total), three per eye (six total), four for the mouth, and one for the tip of the nose.

Review the plot_data function in utils.py to understand how the 30-dimensional training labels in y_train are mapped to facial locations, as this function will prove useful for your pipeline.

(IMPLEMENTATION) Specify the CNN Architecture

In this section, you will specify a neural network for predicting the locations of facial keypoints. Use the code cell below to specify the architecture of your neural network. We have imported some layers that you may find useful for this task, but if you need to use more Keras layers, feel free to import them in the cell.

Your network should accept a $96 \times 96$ grayscale image as input, and it should output a vector with 30 entries, corresponding to the predicted (horizontal and vertical) locations of 15 facial keypoints. If you are not sure where to start, you can find some useful starting architectures in this blog, but you are not permitted to copy any of the architectures that you find online.

In [155]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout, Conv2D
from keras.layers import Flatten, Dense


## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)

model = Sequential()
model.add(Conv2D(16,kernel_size=3,padding='same',data_format='channels_last',activation='relu',
                 input_shape=(96,96,1)))
model.add(MaxPooling2D(pool_size=(2,2),strides=None))

model.add(Conv2D(32,kernel_size=3,padding='same',data_format='channels_last',activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2),strides=None))

model.add(Conv2D(64,kernel_size=3,padding='same',data_format='channels_last',activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2),strides=None))
model.add(MaxPooling2D(pool_size=(2,2),strides=None))

model.add(Flatten())

model.add(Dense(576, activation='relu'))

model.add(Dense(30))

# Summarize the model
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_312 (Conv2D)          (None, 96, 96, 16)        160       
_________________________________________________________________
max_pooling2d_396 (MaxPoolin (None, 48, 48, 16)        0         
_________________________________________________________________
conv2d_313 (Conv2D)          (None, 48, 48, 32)        4640      
_________________________________________________________________
max_pooling2d_397 (MaxPoolin (None, 24, 24, 32)        0         
_________________________________________________________________
conv2d_314 (Conv2D)          (None, 24, 24, 64)        18496     
_________________________________________________________________
max_pooling2d_398 (MaxPoolin (None, 12, 12, 64)        0         
_________________________________________________________________
max_pooling2d_399 (MaxPoolin (None, 6, 6, 64)          0         
_________________________________________________________________
flatten_78 (Flatten)         (None, 2304)              0         
_________________________________________________________________
dense_143 (Dense)            (None, 576)               1327680   
_________________________________________________________________
dense_144 (Dense)            (None, 30)                17310     
=================================================================
Total params: 1,368,286
Trainable params: 1,368,286
Non-trainable params: 0
_________________________________________________________________

Step 6: Compile and Train the Model

After specifying your architecture, you'll need to compile and train the model to detect facial keypoints'

(IMPLEMENTATION) Compile and Train the Model

Use the compile method to configure the learning process. Experiment with your choice of optimizer; you may have some ideas about which will work best (SGD vs. RMSprop, etc), but take the time to empirically verify your theories.

Use the fit method to train the model. Break off a validation set by setting validation_split=0.2. Save the returned History object in the history variable.

Experiment with your model to minimize the validation loss (measured as mean squared error). A very good model will achieve about 0.0015 loss (though it's possible to do even better). When you have finished training, save your model as an HDF5 file with file path my_model.h5.

In [156]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam
from keras.callbacks import ModelCheckpoint

## TODO: Compile the model
def compile_mod(mod, optimizer = 'rmsprop'):
    mod.compile(optimizer=optimizer, loss='mean_squared_error',metrics=['mse'])

## TODO: Train the model
## TODO: Save the model as model.h5 {saves the best model}
def train_mod(mod,x,y,filepath,epochs=30,split=0.2,batch_size=32):
    chkptr = ModelCheckpoint(filepath=filepath,verbose=1,save_best_only=True)
    hist = mod.fit(x,y,epochs=epochs,verbose=1,validation_split=split,batch_size=batch_size,callbacks=[chkptr])
    return hist

optimizers = ['sgd','rmsprop','adagrad','adadelta','adam','adamax','nadam']
epochs = 30
batch_size = 16
history = {}

for opt in optimizers:
    filepath = "saved_mse_models/Mod_"+opt+"_epo"+str(epochs)+"_batch"+str(batch_size)+".h5"
    compile_mod(model,optimizer=opt)
    print("Evaluating - {} - model \n {}".format(opt,filepath))
    history[opt]=train_mod(model,x=X_train,y=y_train,filepath=filepath,epochs=epochs,batch_size=batch_size)
Evaluating - sgd - model 
 saved_mse_models/Mod_sgd_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0910 - mean_squared_error: 0.0910Epoch 00001: val_loss improved from inf to 0.02624, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 0.0903 - mean_squared_error: 0.0903 - val_loss: 0.0262 - val_mean_squared_error: 0.0262
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0123 - mean_squared_error: 0.01 - ETA: 0s - loss: 0.0123 - mean_squared_error: 0.0123Epoch 00002: val_loss improved from 0.02624 to 0.00731, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0122 - mean_squared_error: 0.0122 - val_loss: 0.0073 - val_mean_squared_error: 0.0073
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0072 - mean_squared_error: 0.0072Epoch 00003: val_loss improved from 0.00731 to 0.00661, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0072 - mean_squared_error: 0.0072 - val_loss: 0.0066 - val_mean_squared_error: 0.0066
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0068 - mean_squared_error: 0.0068Epoch 00004: val_loss improved from 0.00661 to 0.00639, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0068 - mean_squared_error: 0.0068 - val_loss: 0.0064 - val_mean_squared_error: 0.0064
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0066 - mean_squared_error: 0.0066Epoch 00005: val_loss improved from 0.00639 to 0.00623, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0066 - mean_squared_error: 0.0066 - val_loss: 0.0062 - val_mean_squared_error: 0.0062
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0064 - mean_squared_error: 0.0064Epoch 00006: val_loss improved from 0.00623 to 0.00606, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0064 - mean_squared_error: 0.0064 - val_loss: 0.0061 - val_mean_squared_error: 0.0061
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0063 - mean_squared_error: 0.0063Epoch 00007: val_loss improved from 0.00606 to 0.00591, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0062 - mean_squared_error: 0.0062 - val_loss: 0.0059 - val_mean_squared_error: 0.0059
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0061 - mean_squared_error: 0.0061Epoch 00008: val_loss improved from 0.00591 to 0.00579, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0061 - mean_squared_error: 0.0061 - val_loss: 0.0058 - val_mean_squared_error: 0.0058
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0060 - mean_squared_error: 0.0060 ETA: 3s - loss: 0.005Epoch 00009: val_loss improved from 0.00579 to 0.00567, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 0.0060 - mean_squared_error: 0.0060 - val_loss: 0.0057 - val_mean_squared_error: 0.0057
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0058 - mean_squared_error: 0.0058Epoch 00010: val_loss improved from 0.00567 to 0.00557, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0058 - mean_squared_error: 0.0058 - val_loss: 0.0056 - val_mean_squared_error: 0.0056
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0057 - mean_squared_error: 0.0057Epoch 00011: val_loss improved from 0.00557 to 0.00548, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0057 - mean_squared_error: 0.0057 - val_loss: 0.0055 - val_mean_squared_error: 0.0055
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0056 - mean_squared_error: 0.0056Epoch 00012: val_loss improved from 0.00548 to 0.00539, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0056 - mean_squared_error: 0.0056 - val_loss: 0.0054 - val_mean_squared_error: 0.0054
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0055 - mean_squared_error: 0.0055Epoch 00013: val_loss improved from 0.00539 to 0.00531, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0055 - mean_squared_error: 0.0055 - val_loss: 0.0053 - val_mean_squared_error: 0.0053
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0054 - mean_squared_error: 0.0054Epoch 00014: val_loss improved from 0.00531 to 0.00524, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0054 - mean_squared_error: 0.0054 - val_loss: 0.0052 - val_mean_squared_error: 0.0052
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0054 - mean_squared_error: 0.0054Epoch 00015: val_loss improved from 0.00524 to 0.00517, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0053 - mean_squared_error: 0.0053 - val_loss: 0.0052 - val_mean_squared_error: 0.0052
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0053 - mean_squared_error: 0.0053Epoch 00016: val_loss improved from 0.00517 to 0.00511, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0053 - mean_squared_error: 0.0053 - val_loss: 0.0051 - val_mean_squared_error: 0.0051
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0052 - mean_squared_error: 0.0052Epoch 00017: val_loss improved from 0.00511 to 0.00504, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0052 - mean_squared_error: 0.0052 - val_loss: 0.0050 - val_mean_squared_error: 0.0050
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0052 - mean_squared_error: 0.0052Epoch 00018: val_loss improved from 0.00504 to 0.00500, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0052 - mean_squared_error: 0.0052 - val_loss: 0.0050 - val_mean_squared_error: 0.0050
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0051 - mean_squared_error: 0.0051Epoch 00019: val_loss improved from 0.00500 to 0.00496, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0051 - mean_squared_error: 0.0051 - val_loss: 0.0050 - val_mean_squared_error: 0.0050
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0051 - mean_squared_error: 0.0051Epoch 00020: val_loss improved from 0.00496 to 0.00490, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0050 - mean_squared_error: 0.0050 - val_loss: 0.0049 - val_mean_squared_error: 0.0049
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0050 - mean_squared_error: 0.0050Epoch 00021: val_loss improved from 0.00490 to 0.00486, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0050 - mean_squared_error: 0.0050 - val_loss: 0.0049 - val_mean_squared_error: 0.0049
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - mean_squared_error: 0.0049Epoch 00022: val_loss improved from 0.00486 to 0.00483, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0050 - mean_squared_error: 0.0050 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - mean_squared_error: 0.0049Epoch 00023: val_loss improved from 0.00483 to 0.00480, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0049 - mean_squared_error: 0.0049 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - mean_squared_error: 0.0049Epoch 00024: val_loss improved from 0.00480 to 0.00475, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0049 - mean_squared_error: 0.0049 - val_loss: 0.0048 - val_mean_squared_error: 0.0048
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - mean_squared_error: 0.0048Epoch 00025: val_loss improved from 0.00475 to 0.00474, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0048 - mean_squared_error: 0.0048 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - mean_squared_error: 0.0048Epoch 00026: val_loss improved from 0.00474 to 0.00470, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0048 - mean_squared_error: 0.0048 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - mean_squared_error: 0.0048Epoch 00027: val_loss improved from 0.00470 to 0.00468, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 0.0048 - mean_squared_error: 0.0048 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0047 - mean_squared_error: 0.0047Epoch 00028: val_loss improved from 0.00468 to 0.00467, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 30s 18ms/step - loss: 0.0047 - mean_squared_error: 0.0047 - val_loss: 0.0047 - val_mean_squared_error: 0.0047
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0047 - mean_squared_error: 0.0047Epoch 00029: val_loss improved from 0.00467 to 0.00463, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0047 - mean_squared_error: 0.0047 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0047 - mean_squared_error: 0.0047Epoch 00030: val_loss improved from 0.00463 to 0.00461, saving model to saved_mse_models/Mod_sgd_epo30_batch16.h5
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0047 - mean_squared_error: 0.0047 - val_loss: 0.0046 - val_mean_squared_error: 0.0046
Evaluating - rmsprop - model 
 saved_mse_models/Mod_rmsprop_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0137 - mean_squared_error: 0.0137Epoch 00001: val_loss improved from inf to 0.01798, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 0.0137 - mean_squared_error: 0.0137 - val_loss: 0.0180 - val_mean_squared_error: 0.0180
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0060 - mean_squared_error: 0.0060 ETA: 0s - loss: 0.0061 - mean_squared_error: 0.Epoch 00002: val_loss improved from 0.01798 to 0.00448, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0060 - mean_squared_error: 0.0060 - val_loss: 0.0045 - val_mean_squared_error: 0.0045
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0050 - mean_squared_error: 0.0050Epoch 00003: val_loss improved from 0.00448 to 0.00392, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0050 - mean_squared_error: 0.0050 - val_loss: 0.0039 - val_mean_squared_error: 0.0039
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0041 - mean_squared_error: 0.0041 - ETA: 12s - loss: 0.0043 - mean_squared_error: Epoch 00004: val_loss improved from 0.00392 to 0.00324, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0041 - mean_squared_error: 0.0041 - val_loss: 0.0032 - val_mean_squared_error: 0.0032
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0034 - mean_squared_error: 0.0034Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0034 - mean_squared_error: 0.0034 - val_loss: 0.0035 - val_mean_squared_error: 0.0035
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0029 - mean_squared_error: 0.0029Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0029 - mean_squared_error: 0.0029 - val_loss: 0.0038 - val_mean_squared_error: 0.0038
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - mean_squared_error: 0.0025Epoch 00007: val_loss improved from 0.00324 to 0.00207, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 0.0025 - mean_squared_error: 0.0025 - val_loss: 0.0021 - val_mean_squared_error: 0.0021
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - mean_squared_error: 0.0022Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0022 - mean_squared_error: 0.0022 - val_loss: 0.0036 - val_mean_squared_error: 0.0036
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - mean_squared_error: 0.0020Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0020 - mean_squared_error: 0.0020 - val_loss: 0.0024 - val_mean_squared_error: 0.0024
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - mean_squared_error: 0.0018Epoch 00010: val_loss improved from 0.00207 to 0.00167, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 0.0018 - mean_squared_error: 0.0018 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - mean_squared_error: 0.0016Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0016 - mean_squared_error: 0.0016 - val_loss: 0.0022 - val_mean_squared_error: 0.0022
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - mean_squared_error: 0.0014Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0014 - mean_squared_error: 0.0014 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - mean_squared_error: 0.0014 ETA: 2s - loss: 0.0013 - meanEpoch 00013: val_loss improved from 0.00167 to 0.00140, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 0.0014 - mean_squared_error: 0.0014 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - mean_squared_error: 0.0013Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0012 - mean_squared_error: 0.0012 - val_loss: 0.0016 - val_mean_squared_error: 0.0016
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0021 - val_mean_squared_error: 0.0021
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0019 - val_mean_squared_error: 0.0019
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - mean_squared_error: 0.0010Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 0.0010 - mean_squared_error: 0.0010 - val_loss: 0.0023 - val_mean_squared_error: 0.0023
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.7553e-04 - mean_squared_error: 9.7553e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 9.7805e-04 - mean_squared_error: 9.7805e-04 - val_loss: 0.0018 - val_mean_squared_error: 0.0018
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.9757e-04 - mean_squared_error: 8.9757e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 8.9895e-04 - mean_squared_error: 8.9895e-04 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.4276e-04 - mean_squared_error: 8.4276e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 8.4247e-04 - mean_squared_error: 8.4247e-04 - val_loss: 0.0015 - val_mean_squared_error: 0.0015
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.0548e-04 - mean_squared_error: 8.0548e-04Epoch 00021: val_loss improved from 0.00140 to 0.00122, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 8.0409e-04 - mean_squared_error: 8.0409e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.7124e-04 - mean_squared_error: 7.7124e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 7.7153e-04 - mean_squared_error: 7.7153e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.1429e-04 - mean_squared_error: 7.1429e-04 ETA: 8s - loss: 6.9988e-04 - mean_squaredEpoch 00023: val_loss improved from 0.00122 to 0.00119, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 7.1308e-04 - mean_squared_error: 7.1308e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 6.8036e-04 - mean_squared_error: 6.8036e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 6.7920e-04 - mean_squared_error: 6.7920e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 6.4031e-04 - mean_squared_error: 6.4031e-04 - ETA: 17s - ETA: 2s - loss: 6.4315e-04 - mean_squEpoch 00025: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 6.3933e-04 - mean_squared_error: 6.3933e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 6.1352e-04 - mean_squared_error: 6.1352e-04 ETA: 3s - loss: 6.0544e-04 - meEpoch 00026: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 6.1363e-04 - mean_squared_error: 6.1363e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.9045e-04 - mean_squared_error: 5.9045e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 5.9001e-04 - mean_squared_error: 5.9001e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.6942e-04 - mean_squared_error: 5.6942e-04Epoch 00028: val_loss improved from 0.00119 to 0.00113, saving model to saved_mse_models/Mod_rmsprop_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 5.6752e-04 - mean_squared_error: 5.6752e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.4926e-04 - mean_squared_error: 5.4926e-04Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 5.4937e-04 - mean_squared_error: 5.4937e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.2865e-04 - mean_squared_error: 5.2865e-04Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 5.2807e-04 - mean_squared_error: 5.2807e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Evaluating - adagrad - model 
 saved_mse_models/Mod_adagrad_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0080 - mean_squared_error: 0.0080Epoch 00001: val_loss improved from inf to 0.00289, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0079 - mean_squared_error: 0.0079 - val_loss: 0.0029 - val_mean_squared_error: 0.0029
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - mean_squared_error: 0.0019Epoch 00002: val_loss improved from 0.00289 to 0.00196, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0019 - mean_squared_error: 0.0019 - val_loss: 0.0020 - val_mean_squared_error: 0.0020
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - mean_squared_error: 0.0012Epoch 00003: val_loss improved from 0.00196 to 0.00174, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 0.0012 - mean_squared_error: 0.0012 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.5995e-04 - mean_squared_error: 9.5995e-04Epoch 00004: val_loss improved from 0.00174 to 0.00167, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 9.5908e-04 - mean_squared_error: 9.5908e-04 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 7.8566e-04 - mean_squared_error: 7.8566e-04Epoch 00005: val_loss improved from 0.00167 to 0.00150, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 22s 13ms/step - loss: 7.8347e-04 - mean_squared_error: 7.8347e-04 - val_loss: 0.0015 - val_mean_squared_error: 0.0015
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 6.6729e-04 - mean_squared_error: 6.6729e-04Epoch 00006: val_loss improved from 0.00150 to 0.00149, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 23s 14ms/step - loss: 6.6789e-04 - mean_squared_error: 6.6789e-04 - val_loss: 0.0015 - val_mean_squared_error: 0.0015
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 5.6222e-04 - mean_squared_error: 5.6222e-04Epoch 00007: val_loss improved from 0.00149 to 0.00142, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 5.6472e-04 - mean_squared_error: 5.6472e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.9112e-04 - mean_squared_error: 4.9112e-04 ETA: 8s - loss: 4.8146e-04 - mean_squared_error: 4. - ETA: 8s - loss: 4.8580e-04 - mean_squaredEpoch 00008: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 4.9204e-04 - mean_squared_error: 4.9204e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 4.4281e-04 - mean_squared_error: 4.4281e-04Epoch 00009: val_loss improved from 0.00142 to 0.00138, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 4.4235e-04 - mean_squared_error: 4.4235e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9355e-04 - mean_squared_error: 3.9355e-04Epoch 00010: val_loss improved from 0.00138 to 0.00137, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 3.9519e-04 - mean_squared_error: 3.9519e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.5453e-04 - mean_squared_error: 3.5453e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 3.5576e-04 - mean_squared_error: 3.5576e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.2249e-04 - mean_squared_error: 3.2249e-04 - ETA: 13s Epoch 00012: val_loss improved from 0.00137 to 0.00137, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 3.2278e-04 - mean_squared_error: 3.2278e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.9246e-04 - mean_squared_error: 2.9246e-04 ETA: 6s - loss: 2.9701e-04 - mean_squared_e - ETA: 4s - loss: 2.9404e-0 - ETA: 1s - loss: 2.9353e-04 - mean_squared_errEpoch 00013: val_loss improved from 0.00137 to 0.00135, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 2.9254e-04 - mean_squared_error: 2.9254e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7101e-04 - mean_squared_error: 2.7101e-04Epoch 00014: val_loss improved from 0.00135 to 0.00134, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 2.7022e-04 - mean_squared_error: 2.7022e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.4671e-04 - mean_squared_error: 2.4671e-04Epoch 00015: val_loss improved from 0.00134 to 0.00132, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 2.4703e-04 - mean_squared_error: 2.4703e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3178e-04 - mean_squared_error: 2.3178e-04Epoch 00016: val_loss improved from 0.00132 to 0.00132, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 2.3201e-04 - mean_squared_error: 2.3201e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1472e-04 - mean_squared_error: 2.1472e-04 ETA: 2s - loss: 2.1572e-04 - mean_sEpoch 00017: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.1504e-04 - mean_squared_error: 2.1504e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.9954e-04 - mean_squared_error: 1.9954e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.0146e-04 - mean_squared_error: 2.0146e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8758e-04 - mean_squared_error: 1.8758e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 1.8742e-04 - mean_squared_error: 1.8742e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.7563e-04 - mean_squared_error: 1.7563e-04Epoch 00020: val_loss improved from 0.00132 to 0.00132, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 1.7571e-04 - mean_squared_error: 1.7571e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.6561e-04 - mean_squared_error: 1.6561e-04Epoch 00021: val_loss improved from 0.00132 to 0.00132, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 1.6556e-04 - mean_squared_error: 1.6556e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.5607e-04 - mean_squared_error: 1.5607e-04Epoch 00022: val_loss improved from 0.00132 to 0.00132, saving model to saved_mse_models/Mod_adagrad_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 1.5600e-04 - mean_squared_error: 1.5600e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.4575e-04 - mean_squared_error: 1.4575e-04Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 1.4631e-04 - mean_squared_error: 1.4631e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3908e-04 - mean_squared_error: 1.3908e-04Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 1.3890e-04 - mean_squared_error: 1.3890e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2932e-04 - mean_squared_error: 1.2932e-04Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.3006e-04 - mean_squared_error: 1.3006e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2342e-04 - mean_squared_error: 1.2342e-04 ETA: 5s -Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.2376e-04 - mean_squared_error: 1.2376e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1685e-04 - mean_squared_error: 1.1685e-04Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 1.1690e-04 - mean_squared_error: 1.1690e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1122e-04 - mean_squared_error: 1.1122e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 1.1101e-04 - mean_squared_error: 1.1101e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0683e-04 - mean_squared_error: 1.0683e-04 ETA: 1s - loss: 1.0627e-04 - mean_squared_errEpoch 00029: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.0685e-04 - mean_squared_error: 1.0685e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0189e-04 - mean_squared_error: 1.0189e-04Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.0173e-04 - mean_squared_error: 1.0173e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Evaluating - adadelta - model 
 saved_mse_models/Mod_adadelta_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.4948e-05 - mean_squared_error: 9.4948e- - ETA: 0s - loss: 9.4816e-05 - mean_squared_error: 9.4816e-05Epoch 00001: val_loss improved from inf to 0.00133, saving model to saved_mse_models/Mod_adadelta_epo30_batch16.h5
1712/1712 [==============================] - 30s 17ms/step - loss: 9.4586e-05 - mean_squared_error: 9.4586e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.2233e-05 - mean_squared_error: 9.2233e-05Epoch 00002: val_loss did not improve
1712/1712 [==============================] - 25s 14ms/step - loss: 9.2208e-05 - mean_squared_error: 9.2208e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.3273e-05 - mean_squared_error: 9.3273e-05Epoch 00003: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 9.3089e-05 - mean_squared_error: 9.3089e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1137e-05 - mean_squared_error: 9.1137e-05Epoch 00004: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 9.0965e-05 - mean_squared_error: 9.0965e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.2396e-05 - mean_squared_error: 9.2396e-05Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 9.2365e-05 - mean_squared_error: 9.2365e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1334e-05 - mean_squared_error: 9.1334e-05Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 9.1267e-05 - mean_squared_error: 9.1267e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.0733e-05 - mean_squared_error: 9.0733e-05Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 9.0497e-05 - mean_squared_error: 9.0497e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1819e-05 - mean_squared_error: 9.1819e-05Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 9.1667e-05 - mean_squared_error: 9.1667e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.0577e-05 - mean_squared_error: 9.0577e-05Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 9.0631e-05 - mean_squared_error: 9.0631e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.9205e-05 - mean_squared_error: 8.9205e-05Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 8.9395e-05 - mean_squared_error: 8.9395e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8800e-05 - mean_squared_error: 8.8800e-05Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 28s 16ms/step - loss: 8.8935e-05 - mean_squared_error: 8.8935e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1483e-05 - mean_squared_error: 9.1483e-05Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 9.1496e-05 - mean_squared_error: 9.1496e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.9688e-05 - mean_squared_error: 8.9688e-05Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.9678e-05 - mean_squared_error: 8.9678e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8362e-05 - mean_squared_error: 8.8362e-05Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.8747e-05 - mean_squared_error: 8.8747e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.0024e-05 - mean_squared_error: 9.0024e-05Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.9806e-05 - mean_squared_error: 8.9806e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8439e-05 - mean_squared_error: 8.8439e-05Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 8.8405e-05 - mean_squared_error: 8.8405e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.9190e-05 - mean_squared_error: 8.9190e-05Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.9358e-05 - mean_squared_error: 8.9358e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8806e-05 - mean_squared_error: 8.8806e-05Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.8794e-05 - mean_squared_error: 8.8794e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8482e-05 - mean_squared_error: 8.8482e-05Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 8.8411e-05 - mean_squared_error: 8.8411e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8981e-05 - mean_squared_error: 8.8981e-05Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.8867e-05 - mean_squared_error: 8.8867e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8766e-05 - mean_squared_error: 8.8766e-05Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.8984e-05 - mean_squared_error: 8.8984e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8516e-05 - mean_squared_error: 8.8516e-05Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 8.8791e-05 - mean_squared_error: 8.8791e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.6995e-05 - mean_squared_error: 8.6995e-05Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 8.7163e-05 - mean_squared_error: 8.7163e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8117e-05 - mean_squared_error: 8.8117e-05Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 27s 16ms/step - loss: 8.8237e-05 - mean_squared_error: 8.8237e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.8032e-05 - mean_squared_error: 8.8032e-05Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.8289e-05 - mean_squared_error: 8.8289e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.7792e-05 - mean_squared_error: 8.7792e-05Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.7739e-05 - mean_squared_error: 8.7739e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.6294e-05 - mean_squared_error: 8.6294e-05Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 8.6272e-05 - mean_squared_error: 8.6272e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.7662e-05 - mean_squared_error: 8.7662e-05Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 8.7681e-05 - mean_squared_error: 8.7681e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.7904e-05 - mean_squared_error: 8.7904e-05Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 8.8027e-05 - mean_squared_error: 8.8027e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.6700e-05 - mean_squared_error: 8.6700e-05Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 8.6794e-05 - mean_squared_error: 8.6794e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Evaluating - adam - model 
 saved_mse_models/Mod_adam_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7337e-04 - mean_squared_error: 2.7337e-04Epoch 00001: val_loss improved from inf to 0.00141, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 29s 17ms/step - loss: 2.7267e-04 - mean_squared_error: 2.7267e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.1264e-04 - mean_squared_error: 3.1264e-04Epoch 00002: val_loss improved from 0.00141 to 0.00139, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 3.1259e-04 - mean_squared_error: 3.1259e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.0548e-04 - mean_squared_error: 3.0548e-04Epoch 00003: val_loss improved from 0.00139 to 0.00136, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 3.0667e-04 - mean_squared_error: 3.0667e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7030e-04 - mean_squared_error: 2.7030e-04Epoch 00004: val_loss improved from 0.00136 to 0.00135, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 2.7011e-04 - mean_squared_error: 2.7011e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1470e-04 - mean_squared_error: 2.1470e-04Epoch 00005: val_loss improved from 0.00135 to 0.00127, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 2.1427e-04 - mean_squared_error: 2.1427e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8875e-04 - mean_squared_error: 1.8875e-04Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 1.8938e-04 - mean_squared_error: 1.8938e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.7210e-04 - mean_squared_error: 1.7210e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.7284e-04 - mean_squared_error: 1.7284e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.9255e-04 - mean_squared_error: 1.9255e-04Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.9262e-04 - mean_squared_error: 1.9262e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8636e-04 - mean_squared_error: 1.8636e-04Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.8650e-04 - mean_squared_error: 1.8650e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.6207e-04 - mean_squared_error: 1.6207e-04Epoch 00010: val_loss improved from 0.00127 to 0.00127, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 1.6193e-04 - mean_squared_error: 1.6193e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3824e-04 - mean_squared_error: 1.3824e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 1.3838e-04 - mean_squared_error: 1.3838e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3407e-04 - mean_squared_error: 1.3407e-04Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 1.3381e-04 - mean_squared_error: 1.3381e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1205e-04 - mean_squared_error: 1.1205e-04Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.1206e-04 - mean_squared_error: 1.1206e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0984e-04 - mean_squared_error: 1.0984e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.0977e-04 - mean_squared_error: 1.0977e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1079e-04 - mean_squared_error: 1.1079e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.1080e-04 - mean_squared_error: 1.1080e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0606e-04 - mean_squared_error: 1.0606e-04 ETA: 1s - loss: 1.0531e-04 - mean_squared_error: Epoch 00016: val_loss improved from 0.00127 to 0.00126, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 1.0602e-04 - mean_squared_error: 1.0602e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0182e-04 - mean_squared_error: 1.0182e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 1.0190e-04 - mean_squared_error: 1.0190e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0292e-04 - mean_squared_error: 1.0292e-04Epoch 00018: val_loss improved from 0.00126 to 0.00123, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 1.0284e-04 - mean_squared_error: 1.0284e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1313e-04 - mean_squared_error: 1.1313e-04Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 1.1323e-04 - mean_squared_error: 1.1323e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2603e-04 - mean_squared_error: 1.2603e-04Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 1.2595e-04 - mean_squared_error: 1.2595e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3365e-04 - mean_squared_error: 1.3365e-04Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 1.3375e-04 - mean_squared_error: 1.3375e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2019e-04 - mean_squared_error: 1.2019e-04Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 1.2032e-04 - mean_squared_error: 1.2032e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0565e-04 - mean_squared_error: 1.0565e-04Epoch 00023: val_loss improved from 0.00123 to 0.00122, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 25s 14ms/step - loss: 1.0556e-04 - mean_squared_error: 1.0556e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.1439e-05 - mean_squared_error: 9.1439e-05Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 9.1294e-05 - mean_squared_error: 9.1294e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.1413e-05 - mean_squared_error: 8.1413e-05Epoch 00025: val_loss improved from 0.00122 to 0.00122, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 8.1504e-05 - mean_squared_error: 8.1504e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.7298e-05 - mean_squared_error: 8.7298e-05Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 21s 12ms/step - loss: 8.7286e-05 - mean_squared_error: 8.7286e-05 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.2712e-05 - mean_squared_error: 9.2712e-05Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 9.3327e-05 - mean_squared_error: 9.3327e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.0586e-04 - mean_squared_error: 1.0586e-04Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.0577e-04 - mean_squared_error: 1.0577e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 9.7436e-05 - mean_squared_error: 9.7436e-05Epoch 00029: val_loss improved from 0.00122 to 0.00121, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 9.7252e-05 - mean_squared_error: 9.7252e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 8.6808e-05 - mean_squared_error: 8.6808e-05Epoch 00030: val_loss improved from 0.00121 to 0.00120, saving model to saved_mse_models/Mod_adam_epo30_batch16.h5
1712/1712 [==============================] - 24s 14ms/step - loss: 8.6762e-05 - mean_squared_error: 8.6762e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Evaluating - adamax - model 
 saved_mse_models/Mod_adamax_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3518e-04 - mean_squared_error: 1.3518e-04Epoch 00001: val_loss improved from inf to 0.00119, saving model to saved_mse_models/Mod_adamax_epo30_batch16.h5
1712/1712 [==============================] - 28s 16ms/step - loss: 1.3452e-04 - mean_squared_error: 1.3452e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.9401e-05 - mean_squared_error: 3.9401e-05Epoch 00002: val_loss improved from 0.00119 to 0.00119, saving model to saved_mse_models/Mod_adamax_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 3.9391e-05 - mean_squared_error: 3.9391e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3313e-05 - mean_squared_error: 2.3313e-05Epoch 00003: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.3314e-05 - mean_squared_error: 2.3314e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8404e-05 - mean_squared_error: 1.8404e-05Epoch 00004: val_loss improved from 0.00119 to 0.00118, saving model to saved_mse_models/Mod_adamax_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 1.8394e-05 - mean_squared_error: 1.8394e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.5237e-05 - mean_squared_error: 1.5237e-05Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 1.5262e-05 - mean_squared_error: 1.5262e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3472e-05 - mean_squared_error: 1.3472e-05Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.3461e-05 - mean_squared_error: 1.3461e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2602e-05 - mean_squared_error: 1.2602e-05Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 25s 14ms/step - loss: 1.2630e-05 - mean_squared_error: 1.2630e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.2105e-05 - mean_squared_error: 1.2105e-05Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.2104e-05 - mean_squared_error: 1.2104e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.1934e-05 - mean_squared_error: 1.1934e-05Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 1.1947e-05 - mean_squared_error: 1.1947e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3151e-05 - mean_squared_error: 1.3151e-05Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.3200e-05 - mean_squared_error: 1.3200e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.4774e-05 - mean_squared_error: 1.4774e-05Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.4794e-05 - mean_squared_error: 1.4794e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.7252e-05 - mean_squared_error: 1.7252e-05Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 1.7311e-05 - mean_squared_error: 1.7311e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3478e-05 - mean_squared_error: 2.3478e-05Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.3460e-05 - mean_squared_error: 2.3460e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5815e-05 - mean_squared_error: 2.5815e-05Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.5743e-05 - mean_squared_error: 2.5743e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5013e-05 - mean_squared_error: 2.5013e-05Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.5102e-05 - mean_squared_error: 2.5102e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.6305e-05 - mean_squared_error: 2.6305e-05Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.6307e-05 - mean_squared_error: 2.6307e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.6471e-05 - mean_squared_error: 2.6471e-05Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.6435e-05 - mean_squared_error: 2.6435e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.6505e-05 - mean_squared_error: 2.6505e-05Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.6539e-05 - mean_squared_error: 2.6539e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5621e-05 - mean_squared_error: 2.5621e-05Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.5673e-05 - mean_squared_error: 2.5673e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.6122e-05 - mean_squared_error: 2.6122e-05Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.6073e-05 - mean_squared_error: 2.6073e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.6956e-05 - mean_squared_error: 2.6956e-05Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.6913e-05 - mean_squared_error: 2.6913e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3959e-05 - mean_squared_error: 2.3959e-05Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 23s 13ms/step - loss: 2.4002e-05 - mean_squared_error: 2.4002e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.4546e-05 - mean_squared_error: 2.4546e-05Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.4529e-05 - mean_squared_error: 2.4529e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.4547e-05 - mean_squared_error: 2.4547e-05Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.4507e-05 - mean_squared_error: 2.4507e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.1782e-05 - mean_squared_error: 2.1782e-05Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.1797e-05 - mean_squared_error: 2.1797e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.4400e-05 - mean_squared_error: 2.4400e-05Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 2.4430e-05 - mean_squared_error: 2.4430e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5861e-05 - mean_squared_error: 2.5861e-05Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 25s 14ms/step - loss: 2.5829e-05 - mean_squared_error: 2.5829e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.4697e-05 - mean_squared_error: 2.4697e-05Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 26s 15ms/step - loss: 2.4729e-05 - mean_squared_error: 2.4729e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5618e-05 - mean_squared_error: 2.5618e-05Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 25s 14ms/step - loss: 2.5577e-05 - mean_squared_error: 2.5577e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.2110e-05 - mean_squared_error: 2.2110e-05Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.2089e-05 - mean_squared_error: 2.2089e-05 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Evaluating - nadam - model 
 saved_mse_models/Mod_nadam_epo30_batch16.h5
Train on 1712 samples, validate on 428 samples
Epoch 1/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.5919e-04 - mean_squared_error: 3.5919e-04Epoch 00001: val_loss improved from inf to 0.00129, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 28s 17ms/step - loss: 3.5738e-04 - mean_squared_error: 3.5738e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 2/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.6186e-04 - mean_squared_error: 3.6186e-04Epoch 00002: val_loss did not improve
1712/1712 [==============================] - 25s 15ms/step - loss: 3.6201e-04 - mean_squared_error: 3.6201e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 3/30
1696/1712 [============================>.] - ETA: 0s - loss: 3.5583e-04 - mean_squared_error: 3.5583e-04Epoch 00003: val_loss improved from 0.00129 to 0.00128, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 3.5483e-04 - mean_squared_error: 3.5483e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 4/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.7936e-04 - mean_squared_error: 2.7936e-04Epoch 00004: val_loss improved from 0.00128 to 0.00125, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 27s 16ms/step - loss: 2.7883e-04 - mean_squared_error: 2.7883e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 5/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0706e-04 - mean_squared_error: 2.0706e-04Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.0724e-04 - mean_squared_error: 2.0724e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 6/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.5920e-04 - mean_squared_error: 2.5920e-04Epoch 00006: val_loss improved from 0.00125 to 0.00122, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 2.5812e-04 - mean_squared_error: 2.5812e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 7/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0819e-04 - mean_squared_error: 2.0819e-04Epoch 00007: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.1290e-04 - mean_squared_error: 2.1290e-04 - val_loss: 0.0014 - val_mean_squared_error: 0.0014
Epoch 8/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.3991e-04 - mean_squared_error: 2.3991e-04Epoch 00008: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.4016e-04 - mean_squared_error: 2.4016e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 9/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8819e-04 - mean_squared_error: 1.8819e-04Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 1.8894e-04 - mean_squared_error: 1.8894e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 10/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.8835e-04 - mean_squared_error: 1.8835e-04Epoch 00010: val_loss improved from 0.00122 to 0.00121, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 25s 15ms/step - loss: 1.8799e-04 - mean_squared_error: 1.8799e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 11/30
1696/1712 [============================>.] - ETA: 0s - loss: 2.0522e-04 - mean_squared_error: 2.0522e-04Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 2.0556e-04 - mean_squared_error: 2.0556e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 12/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.7517e-04 - mean_squared_error: 1.7517e-04Epoch 00012: val_loss improved from 0.00121 to 0.00120, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 1.7626e-04 - mean_squared_error: 1.7626e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 13/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.5419e-04 - mean_squared_error: 1.5419e-04Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 22s 13ms/step - loss: 1.5365e-04 - mean_squared_error: 1.5365e-04 - val_loss: 0.0013 - val_mean_squared_error: 0.0013
Epoch 14/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3509e-04 - mean_squared_error: 1.3509e-04Epoch 00014: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.3500e-04 - mean_squared_error: 1.3500e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 15/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3619e-04 - mean_squared_error: 1.3619e-04Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 23s 14ms/step - loss: 1.3590e-04 - mean_squared_error: 1.3590e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 16/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.3444e-04 - mean_squared_error: 1.3444e-04Epoch 00016: val_loss improved from 0.00120 to 0.00115, saving model to saved_mse_models/Mod_nadam_epo30_batch16.h5
1712/1712 [==============================] - 26s 15ms/step - loss: 1.3444e-04 - mean_squared_error: 1.3444e-04 - val_loss: 0.0011 - val_mean_squared_error: 0.0011
Epoch 17/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.4035e-04 - mean_squared_error: 1.4035e-04Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.4116e-04 - mean_squared_error: 1.4116e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 18/30
1696/1712 [============================>.] - ETA: 0s - loss: 1.6072e-04 - mean_squared_error: 1.6072e-04Epoch 00018: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 1.6073e-04 - mean_squared_error: 1.6073e-04 - val_loss: 0.0012 - val_mean_squared_error: 0.0012
Epoch 19/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0055 - mean_squared_error: 0.0055Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0055 - mean_squared_error: 0.0055 - val_loss: 0.0040 - val_mean_squared_error: 0.0040
Epoch 20/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0035 - mean_squared_error: 0.0035Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0035 - mean_squared_error: 0.0035 - val_loss: 0.0031 - val_mean_squared_error: 0.0031
Epoch 21/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0027 - mean_squared_error: 0.0027Epoch 00021: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0027 - mean_squared_error: 0.0027 - val_loss: 0.0026 - val_mean_squared_error: 0.0026
Epoch 22/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - mean_squared_error: 0.0023Epoch 00022: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0022 - mean_squared_error: 0.0022 - val_loss: 0.0024 - val_mean_squared_error: 0.0024
Epoch 23/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - mean_squared_error: 0.0020Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0020 - mean_squared_error: 0.0020 - val_loss: 0.0022 - val_mean_squared_error: 0.0022
Epoch 24/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - mean_squared_error: 0.0017Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0017 - mean_squared_error: 0.0017 - val_loss: 0.0020 - val_mean_squared_error: 0.0020
Epoch 25/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - mean_squared_error: 0.0016Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0016 - mean_squared_error: 0.0016 - val_loss: 0.0019 - val_mean_squared_error: 0.0019
Epoch 26/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - mean_squared_error: 0.0014Epoch 00026: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0014 - mean_squared_error: 0.0014 - val_loss: 0.0019 - val_mean_squared_error: 0.0019
Epoch 27/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - mean_squared_error: 0.0013Epoch 00027: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0013 - mean_squared_error: 0.0013 - val_loss: 0.0018 - val_mean_squared_error: 0.0018
Epoch 28/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - mean_squared_error: 0.0012Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0012 - mean_squared_error: 0.0012 - val_loss: 0.0018 - val_mean_squared_error: 0.0018
Epoch 29/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0017 - val_mean_squared_error: 0.0017
Epoch 30/30
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - mean_squared_error: 0.0011Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 24s 14ms/step - loss: 0.0011 - mean_squared_error: 0.0011 - val_loss: 0.0018 - val_mean_squared_error: 0.0018

Step 7: Visualize the Loss and Test Predictions

(IMPLEMENTATION) Answer a few questions and visualize the loss

Question 1: Outline the steps you took to get to your final neural network architecture and your reasoning at each step.

Answer:

  1. Started with an approach of 4 convNets + 3 Dense layers to end and tried with multiple combination of maxpooling and global average pooling.
  2. First observation was that, too many Dense layers at the end did not add any benefit to the performance. So reduced it to a single Dense layer before the final Dense(30).
  3. 4/5 Convnets sandwiched with maxpooling + flatten + Dense(512) + Dense(30) did give some reasonable performance below a val_mse of 0.0020.
  4. At this stage, several dropout layers before and aftern Flatten did not improve performance.
  5. Applied fine tuning with padding='valid' for the final convnet and did not improve performance.
  6. The observations 4 & 5 lead to a conclusion that droping or ignoring some pixels might not lead to a good model.
  7. Tried reducing the convnets to 3 and added 2 max pooling layers. A Evaluated Dense(400) to Dense(700) range to see if there is a significant change in performance and it turns out that there is some meaningful improvement between the range of 512 - 600. From this observation and from point 6, A mathematically choice of Dense of (576) which is 1/4th of 2304 (from Flatten) was applied to get the best model.
  8. A final trial was made between batch size of 32 and 16 , for epochs = 30. It turns out that the batch size 16 worked out better.

Note: Brute force method of running trials using higher epochs was avoided.
Note : Batch size 16, repeatedly failed in AWS env. Hence used a local PC to achive this trial.

Question 2: Defend your choice of optimizer. Which optimizers did you test, and how did you determine which worked best?

Answer:

Using a set of custom methods, a set of optimizers ['sgd','rmsprop','adagrad','adadelta','adam','adamax','nadam'] were tested. From the image below, it turns out 'adamax' has the least variation of val_mse among all. Hence, chose Adamax.

Use the code cell below to plot the training and validation loss of your neural network. You may find this resource useful.

In [163]:
## TODO: Visualize the training and validation loss of your neural network

# list all data in history
# summarize history for mse
for name in optimizers:
    plt.plot(history[name].history['val_mean_squared_error'])
plt.title('MSE by models')
plt.ylabel('Validation MSE')
plt.xlabel('epoch')
plt.ylim(0.0010,0.0015)
plt.subplots_adjust(left=0.0, right=2.0, bottom=0.0, top=2.0)
plt.legend(optimizers, loc='center left', bbox_to_anchor=(1, 0.5))
plt.show()
In [294]:
#Select Final model
final_mod = "saved_mse_models/Mod_adamax_epo30_batch16.h5"
model.load_weights(final_mod)

Question 3: Do you notice any evidence of overfitting or underfitting in the above plot? If so, what steps have you taken to improve your model? Note that slight overfitting or underfitting will not hurt your chances of a successful submission, as long as you have attempted some solutions towards improving your model (such as regularization, dropout, increased/decreased number of layers, etc).

Answer:

As explained in the answer for Question 1, several approaches were taken to improve the model (to overfit) such as:

  1. Decreased the number of convnets
  2. Tried out dropouts (did not help)
  3. Tried out a stride value of 3. (did not help, as it again proved to understand that loosing/droping any pixel did not help throughout my approach)

Visualize a Subset of the Test Predictions

Execute the code cell below to visualize your model's predicted keypoints on a subset of the testing images.

In [295]:
y_test = model.predict(X_test)
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_test[i], y_test[i], ax)

Step 8: Complete the pipeline

With the work you did in Sections 1 and 2 of this notebook, along with your freshly trained facial keypoint detector, you can now complete the full pipeline. That is given a color image containing a person or persons you can now

  • Detect the faces in this image automatically using OpenCV
  • Predict the facial keypoints in each face detected in the image
  • Paint predicted keypoints on each face detected

In this Subsection you will do just this!

(IMPLEMENTATION) Facial Keypoints Detector

Use the OpenCV face detection functionality you built in previous Sections to expand the functionality of your keypoints detector to color images with arbitrary size. Your function should perform the following steps

  1. Accept a color image.
  2. Convert the image to grayscale.
  3. Detect and crop the face contained in the image.
  4. Locate the facial keypoints in the cropped image.
  5. Overlay the facial keypoints in the original (color, uncropped) image.

Note: step 4 can be the trickiest because remember your convolutional network is only trained to detect facial keypoints in $96 \times 96$ grayscale images where each pixel was normalized to lie in the interval $[0,1]$, and remember that each facial keypoint was normalized during training to the interval $[-1,1]$. This means - practically speaking - to paint detected keypoints onto a test face you need to perform this same pre-processing to your candidate face - that is after detecting it you should resize it to $96 \times 96$ and normalize its values before feeding it into your facial keypoint detector. To be shown correctly on the original image the output keypoints from your detector then need to be shifted and re-normalized from the interval $[-1,1]$ to the width and height of your detected face.

When complete you should be able to produce example images like the one below

In [296]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')


# Convert the image to RGB colorspace
image_copy = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# plot our image
fig = plt.figure(figsize = (9,9))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('image copy')
ax1.imshow(image_copy)
Out[296]:
<matplotlib.image.AxesImage at 0x23cb3aefa20>
In [297]:
### TODO: Use the face detection code we saw in Section 1 with your trained conv-net 

gray = cv2.cvtColor(image_copy, cv2.COLOR_RGB2GRAY)

#detect faces
fcs = face_cascade.detectMultiScale(gray,1.3,6)
image_f = np.copy(image_copy)

#build rectangles
for(x,y,w,h) in fcs:
    cv2.rectangle(image_f,(x,y),(x+w,y+h),(255,0,0),3)

fig = plt.figure(figsize = (20,20))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_f)
Out[297]:
<matplotlib.image.AxesImage at 0x23c8029d860>
In [298]:
## TODO : Paint the predicted keypoints on the test image

# reshape the faces to 96 , 96 in an array
faces_96 = np.ndarray(shape=(len(fcs),96,96,1),dtype=float,order='F')

# Paint the facial points overlaying the original image
fig = plt.figure(figsize=(20,20))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

for (x,y,w,h) in fcs:
    face = gray[y:y+h,x:x+w]
    # nomalize to [0,1]
    face_96 = cv2.resize(face,(96,96), interpolation = cv2.INTER_CUBIC) / 255
    faces_96[0,:,:,0]=face_96
    # predict face points for each captured face
    face_pts = model.predict(faces_96)[0]
    # using from utils.py
    ax1.scatter(face_pts[0::2] * (w / 2) + (w / 2) + x,
                face_pts[1::2] * (h / 2) + (h / 2) + y,
                marker='o', c='c', s=20)
ax1.imshow(image_f)
Out[298]:
<matplotlib.image.AxesImage at 0x23c6c32a6d8>

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add facial keypoint detection to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for keypoint detection and marking in the previous exercise and you should be good to go!

In [ ]:
import cv2
import time 
from keras.models import load_model
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # keep video stream open
    while rval:
        # plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # destroy windows
            cv2.destroyAllWindows()
            
            # hack from stack overflow for making sure window closes on osx --> https://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()  
In [ ]:
# Run your keypoint face painter
laptop_camera_go()

(Optional) Further Directions - add a filter using facial keypoints

Using your freshly minted facial keypoint detector pipeline you can now do things like add fun filters to a person's face automatically. In this optional exercise you can play around with adding sunglasses automatically to each individual's face in an image as shown in a demonstration image below.

To produce this effect an image of a pair of sunglasses shown in the Python cell below.

In [299]:
import matplotlib.patches as patches

#Load in sunglasses image - note the usage of the special option
# cv2.IMREAD_UNCHANGED, this option is used because the sunglasses 
# image has a 4th channel that allows us to control how transparent each pixel in the image is
sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)

# Plot the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.imshow(sunglasses)
# used help from online on this approach of using the rectangle patches, matrix affline transformation etc.,

glass_tri_vx = np.array([(280,150), (2800,150), (280,600)]).astype(np.float32)
ax1.add_patch(patches.Rectangle((280, 150),2800-280, 600-150, alpha=0.8))
ax1.axis('off');

This image is placed over each individual's face using the detected eye points to determine the location of the sunglasses, and eyebrow points to determine the size that the sunglasses should be for each person (one could also use the nose point to determine this).

Notice that this image actually has 4 channels, not just 3.

In [300]:
# Print out the shape of the sunglasses image
print ('The sunglasses image has shape: ' + str(np.shape(sunglasses)))
The sunglasses image has shape: (1123, 3064, 4)

It has the usual red, blue, and green channels any color image has, with the 4th channel representing the transparency level of each pixel in the image. Here's how the transparency channel works: the lower the value, the more transparent the pixel will become. The lower bound (completely transparent) is zero here, so any pixels set to 0 will not be seen.

This is how we can place this image of sunglasses on someone's face and still see the area around of their face where the sunglasses lie - because these pixels in the sunglasses image have been made completely transparent.

Lets check out the alpha channel of our sunglasses image in the next Python cell. Note because many of the pixels near the boundary are transparent we'll need to explicitly print out non-zero values if we want to see them.

In [301]:
# Print out the sunglasses transparency (alpha) channel
alpha_channel = sunglasses[:,:,3]
print ('the alpha channel here looks like')
print (alpha_channel)

# Just to double check that there are indeed non-zero values
# Let's find and print out every value greater than zero
values = np.where(alpha_channel != 0)
print ('\n the non-zero values of the alpha channel look like')
print (values)
the alpha channel here looks like
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

 the non-zero values of the alpha channel look like
(array([  17,   17,   17, ..., 1109, 1109, 1109], dtype=int64), array([ 687,  688,  689, ..., 2376, 2377, 2378], dtype=int64))

This means that when we place this sunglasses image on top of another image, we can use the transparency channel as a filter to tell us which pixels to overlay on a new image (only the non-transparent ones with values greater than zero).

One last thing: it's helpful to understand which keypoint belongs to the eyes, mouth, etc. So, in the image below, we also display the index of each facial keypoint directly on the image so that you can tell which keypoints are for the eyes, eyebrows, etc.

With this information, you're well on your way to completing this filtering task! See if you can place the sunglasses automatically on the individuals in the image loaded in / shown in the next Python cell.

In [302]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Plot the image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[302]:
<matplotlib.image.AxesImage at 0x23c80313a20>
In [303]:
## (Optional) TODO: Use the face detection code we saw in Section 1 with your trained conv-net to put
## sunglasses on the individuals in our test image
fig = plt.figure(figsize = (20,20))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
#ax1.imshow(image) # used for trials - setting up patches using eyepoints

for (x,y,w,h) in fcs:
    face = gray[y:y+h,x:x+w]
    # nomalize to [0,1]
    face_96 = cv2.resize(face,(96,96), interpolation = cv2.INTER_CUBIC) / 255
    faces_96[0,:,:,0]=face_96
    # predict face points for each captured face
    face_pts = model.predict(faces_96)[0]
    # x points remapped to original image 
    face_pts[0::2] = face_pts[0::2] * (w / 2) + (w / 2) + x
    # y points remapped to original image 
    face_pts[1::2] = face_pts[1::2] * (h / 2) + (h / 2) + y
    
    # Get eye points
    eye_pts = []
    for (x_pt,y_pt) in zip(face_pts[0:20:2],face_pts[1:20:2]):
        eye_pts.append((x_pt,y_pt))
        
    # Calculate rectangle around eyes
    eye_Rect = cv2.boundingRect(np.array(eye_pts).astype(np.float32))

    # test the eye Rectangle using a patch ## trial
    #ax1.add_patch(patches.Rectangle((eye_Rect[0],eye_Rect[1]),eye_Rect[2],eye_Rect[3]))
    
    # triangle vertices of eyes
    eyes_tri_vx = np.array([(eye_Rect[0],eye_Rect[1]), 
                            (eye_Rect[0]+eye_Rect[2],eye_Rect[1]), 
                            (eye_Rect[0],eye_Rect[1]+eye_Rect[3])]).astype(np.float32)
    
    #Affine transform matrix from glasses and eyes vx
    map_matrix = cv2.getAffineTransform(glass_tri_vx, eyes_tri_vx)
    
    # Transformation on sunglass
    tx_sunglasses = cv2.warpAffine(sunglasses, map_matrix, (image.shape[1], image.shape[0]))
    
    # Build a binary mask on the sunglasses
    tx_sunglasses_mask = tx_sunglasses[:,:,3] > 0
    # Overwrite pixels using glasses mask
    image[:,:,:][tx_sunglasses_mask] = tx_sunglasses[:,:,0:3][tx_sunglasses_mask]

ax1.imshow(image)
Out[303]:
<matplotlib.image.AxesImage at 0x23c82c6b048>

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add the sunglasses filter to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for adding sunglasses to someone's face in the previous optional exercise and you should be good to go!

In [ ]:
import cv2
import time 
from keras.models import load_model
import numpy as np

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [ ]:
# Load facial landmark detector model
model = load_model('my_model.h5')

# Run sunglasses painter
laptop_camera_go()